package com.sqrj.phoneorder.Controller;

import com.sqrj.phoneorder.common.JsonData;
import com.sqrj.phoneorder.model.SendChart;
import com.sqrj.phoneorder.model.WxOrderUnit;
import com.sqrj.phoneorder.param.SendCountParam;
import com.sqrj.phoneorder.service.SendTruckOUTService;
import com.sqrj.phoneorder.service.WxHntRwdService;
import com.sqrj.phoneorder.service.WxOrderUnitService;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

@RestController
public class SendCountChartController {

    @Resource
    private SendTruckOUTService sendTruckOUTService;

    @Resource
    private WxHntRwdService wxHntRwdService;

    @Resource
    private WxOrderUnitService wxOrderUnitService;

//    查询搅拌站图表数据
    @PostMapping("/querySendCountChart")
    public Map<String, Object> querySendCountChart(@RequestBody Map<String, Object> map) {
        String wxUserCode = (String) map.get("wxUserCode");
        System.out.println("拦截搅拌站code..." + wxUserCode);
        Map<String, Object> modelMap = new HashMap<String, Object>();
        //初始化数据为0.0
        Double[] data1 = new Double[]{0.0, 0.0, 0.0, 0.0};
        List<SendChart> SCCPList = wxHntRwdService.querySendChartbyCode(wxUserCode);
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        String date3 = sdf.format(cal.getTime());
        cal.add(Calendar.DATE, 1);
        String date4 = sdf.format(cal.getTime());
        cal.add(Calendar.DATE, -2);
        String date2 = sdf.format(cal.getTime());
        cal.add(Calendar.DATE, -1);
        String date1 = sdf.format(cal.getTime());
        System.out.println("size" + SCCPList.size());

        for (int i = 0; i < SCCPList.size(); i++) {
            if (SCCPList.get(i).getSendDate().equals(date1)) {
                data1[0] = SCCPList.get(i).getOrderQuantity();
            } else if (SCCPList.get(i).getSendDate().equals(date2)) {
                data1[1] = SCCPList.get(i).getOrderQuantity();
                System.out.println("data12" + data1[2]);
            } else if (SCCPList.get(i).getSendDate().equals(date3)) {
                data1[2] = SCCPList.get(i).getOrderQuantity();
                System.out.println("---------SCPList.get(i).getOrderQuantity();------" + SCCPList.get(i).getOrderQuantity() + "---" + data1[2]);
            } else if (SCCPList.get(i).getSendDate().equals(date4)) {
                data1[3] = SCCPList.get(i).getOrderQuantity();
                System.out.println("dat3a2" + data1[2]);
            }
        }

        modelMap.put("data1", data1);
        return modelMap;
    }

    //按客户
    @PostMapping("/queryCustomerCount")
    public JsonData queryCustomerCount(@RequestBody SendCountParam sendCountParam) {
        return JsonData.success(sendTruckOUTService.getSendCountByCustomer(sendCountParam));
    }

    //查询客户集合
    @PostMapping("/queryCustomerList")
    public JsonData queryCustomerList(@RequestBody SendCountParam sendCountParam) {

        return JsonData.success(sendTruckOUTService.queryCustomerList(sendCountParam));
    }

    //按施工单位
    @PostMapping("/queryProUnitCount")
    public JsonData getSendCountByProUnit(@RequestBody SendCountParam sendCountParam) {

        return JsonData.success(sendTruckOUTService.getSendCountByProUnit(sendCountParam));
    }

    //按车牌号
    @PostMapping("/queryTruckCount")
    public JsonData getSendCountByTruck(@RequestBody SendCountParam sendCountParam) {

        return JsonData.success(sendTruckOUTService.getSendCountByTruck(sendCountParam));
    }

    //查询车牌号集合
    @PostMapping("/queryTruckList")
    public JsonData queryTruckList(@RequestBody SendCountParam sendCountParam) {

        return JsonData.success(sendTruckOUTService.queryTruckList(sendCountParam));
    }

    //按发货人
    @PostMapping("/querySenderCount")
    public JsonData getSendCountBySender(@RequestBody SendCountParam sendCountParam) {

        return JsonData.success(sendTruckOUTService.getSendCountBySender(sendCountParam));
    }

    //查询发货人集合
    @PostMapping("/querySenderList")
    public JsonData querySenderList(@RequestBody SendCountParam sendCountParam) {

        return JsonData.success(sendTruckOUTService.querySenderList(sendCountParam));
    }

    //按操作员
    @PostMapping("/queryOperatorCount")
    public JsonData getSendCountByOperator(@RequestBody SendCountParam sendCountParam) {

        return JsonData.success(sendTruckOUTService.getSendCountByOperator(sendCountParam));
    }

    //查询操作员集合
    @PostMapping("/queryOperatorList")
    public JsonData queryOperatorList(@RequestBody SendCountParam sendCountParam) {

        return JsonData.success(sendTruckOUTService.queryOperatorList(sendCountParam));
    }

    //按现场联系人
    @PostMapping("/queryLinkManCount")
    public JsonData getSendCountByLinkMan(@RequestBody SendCountParam sendCountParam) {

         return JsonData.success(sendTruckOUTService.getSendCountByLinkMan(sendCountParam));
    }

    //查询现场联系人集合
    @PostMapping("/queryLinkManList")
    public JsonData queryLinkManList(@RequestBody SendCountParam sendCountParam) {

        return JsonData.success(sendTruckOUTService.queryLinkManList(sendCountParam));
    }

    //按生产线
    @PostMapping("/queryProLineCount")
    @ResponseBody
    public JsonData getSendCountByProLine(@RequestBody SendCountParam sendCountParam) {

        return JsonData.success(sendTruckOUTService.getSendCountByProLine(sendCountParam));
    }

    //按强度等级
    @PostMapping("/queryLevelCount")
    @ResponseBody
    public JsonData getSendCountByLevel(@RequestBody SendCountParam sendCountParam) {

        return JsonData.success(sendTruckOUTService.getSendCountByLevel(sendCountParam));
    }

}

